package com.ebj.demo.thrift;

import com.ebj.demo.thrift.constant.GlobalConstants;
import com.ebj.demo.thrift.generate.HelloMartinService;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

/**
 * Created by xiangyongzhou on 2017/7/5.
 */
public class ClientApp
{
    public static void main(String[] args)
    {
        ClientApp clientApp = new ClientApp();
        clientApp.startClient("martin2");
    }

    public void startClient(String userName)
    {
        TTransport tTransport = new TSocket(GlobalConstants.SERVER_IP, GlobalConstants.SERVER_PORT, GlobalConstants.TIMEOUT);
        TProtocol protocol = new TCompactProtocol(tTransport);
        HelloMartinService.Client client = new HelloMartinService.Client(protocol);
        try {
            tTransport.open();
            String result = client.sayHello(userName);
            System.out.println("result = " + result);
        }
        catch (TTransportException e) {
            e.printStackTrace();
        }
        catch (TException e) {
            e.printStackTrace();
        }
    }
}
